package cn.tedu.egweibo1.controller;

import cn.tedu.egweibo1.base.reponse.JsonResult;
import cn.tedu.egweibo1.base.reponse.StatusCode;
import cn.tedu.egweibo1.mapper.UserMapper;
import cn.tedu.egweibo1.pojo.datatransferobject.UserAddParam;
import cn.tedu.egweibo1.pojo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @PostMapping("/add")
    public JsonResult userAddMessage(@RequestBody UserAddParam userAddParam){
        log.debug("userAddParam:"+userAddParam);
        User user = new User();
        BeanUtils.copyProperties(userAddParam,user);
        user.setCreateTime(new Date());
        log.debug("user:"+user);
        int num = userMapper.addUser(user);
        if (num > 0){
            return JsonResult.ok();
        }else {
            return new JsonResult(StatusCode.OPERATION_FAILED);
        }
    }
}
